﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace KabiManagementWeb.Models
{
    public class SalaryFacade
    {
        private KBManagementDataContext context;
        public SalaryFacade(DBUtils.DBType type)
        {
            context = DBUtils.GetContext(type);
        }
        public SalaryFacade()
        {

        }
        public SalaryFacade(KBManagementDataContext context)
        {
            this.context = context;
        }


        public List<Pay_Salary> GetListPaySalary(int month, int year)
        {

            var salaries = context.Pay_Salaries.Where(x => x.PayMonth == month && x.PayYear == year);
            if (salaries.ToList() != null)
            {
                return salaries.ToList();
            }

            return new List<Pay_Salary>();
        }
        public decimal GetTotalAmount(int month, int year)
        {
            var salaries = context.Pay_Salaries.Where(x => x.PayMonth == month && x.PayYear == year);
            if (salaries.Sum(x => x.TotalAmount).HasValue)
                return salaries.Sum(x => x.TotalAmount).Value;

            return 0;
        }
        public decimal GetTotalTip(int month, int year)
        {
            var salaries = context.Pay_Salaries.Where(x => x.PayMonth == month && x.PayYear == year);
            if (salaries.Sum(x => x.TotalTipMoney).HasValue)
                return salaries.Sum(x => x.TotalTipMoney).Value;

            return 0;
        }
        public decimal GetTotalReward(int month, int year)
        {
            var salaries = context.Pay_Salaries.Where(x => x.PayMonth == month && x.PayYear == year);
            if (salaries.Sum(x => x.TotalRewardMoney).HasValue)
                return salaries.Sum(x => x.TotalRewardMoney).Value;

            return 0;
        }
        public decimal GetTotalPenalty(int month, int year)
        {
            var salaries = context.Pay_Salaries.Where(x => x.PayMonth == month && x.PayYear == year);
            if (salaries.Sum(x => x.TotalPenaltyMoney).HasValue)
                return salaries.Sum(x => x.TotalPenaltyMoney).Value;

            return 0;
        }
    }
}
